/**
 * Created by Zzhk on 2017/6/30.
 */
$(function () {
    var fn = ABUS.Fn;
    var listData = [];

    document.addEventListener('touchmove', function (e) {
        e.preventDefault();
        isDrag = true;
    }, {passive: false});

    $('#sorting').on('touchend', function (e) {
        var $modal = $('.sorting');
        if ($modal.is(":visible")) {
            $modal.hide();
        }
        else {
            $modal.show();
        }
        e.stopPropagation();
    });
    $('body').on('touchend', function () {
        $('.sorting').hide();
    });

    fn.get({
        url: "/leader/order/acceptedOrders",
        data: {
            "searchValue": "",
            "orderBy": "",//1业务类型 2剩余时间 3开始时间
            "orderType": ""
        },
        success: function (data) {
            init(data);
        }
    });

    $("#being_process").on("touchend", "li", function () {
        if (isDrag) {
            isDrag = false;
            return true;
        }
        var data = listData[$(this).index()];
        data.p1 = $(this).data('p1');
        data.p2 = $(this).data('p2');
        fn.page_goto({
            url : "./zuzhang_banli_pendingPay.html",
            data : data
        })
    });
    $(".search:first").on("touchend", function () {
        fn.page_goto({
            url: "./zuzhang_banli_search.html"
        })
    });

    $("#sorting_list").on("touchend", "li", function () {
        fn.get({
            url: "/leader/order/acceptedOrders",
            data: {
                "searchValue": "",
                "orderBy": $(this).data('value'),//1业务类型 2剩余时间 3开始时间
                "orderType": "ASC"
            },
            success: function (data) {
                init(data)
            }
        });
    });

    function init(data) {
        var con = $("#being_process");
        con.renderTemp(data);
        listData = data.data;
        new IScroll('#being_process', {mouseWheel: true});

        con.find('li').each(function (i) {
            var $el = $(this).find('[data-time]');
            if(data.data[i].situation === -1){
                $el.text("暂停计时")
            }else{
                if ($el.length > 0 && $el.data('time'))
                    fn.countDown($el.data('time'), function (time) {
                        $el.text(time)
                    })
            }
        })
    }
});